/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
 */

package org.opengauss.provider;

import org.opengauss.vo.TableOrderVo;
import org.apache.ibatis.jdbc.SQL;

/**
 * description:this for TableOrderProvider Class
 * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021.
 *
 * @author Administrator
 * @version [openGauss_debug 0.0.1 2021/5/8]
 * @since 2021/5/8
 */
public class TableOrderProvider implements BaseProvider<TableOrderVo> {
    @Override
    public String getTableName() {
        return "t_order";
    }

    @Override
    public String getCreateColumns() {
        return TableOrderVo.createColumns();
    }

    public String maxId() {
        return new SQL() {{
            SELECT("case when max(order_id) is null then 0 else max(order_id)+1 end as maxId");
            FROM(getTableName());
        }}.toString();
    }

    public String add(TableOrderVo insertVo) {
        return new SQL() {{
            INSERT_INTO(getTableName());
            VALUES("order_id", "#{orderId}");
            VALUES("user_id", "#{userId}");
            VALUES("data", "#{data}");
        }}.toString();
    }
}
